package com.whu.waterworks.action;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.dto.QualityReportDataDto;
import com.whu.waterworks.model.Antisseptic;
import com.whu.waterworks.model.QualityNonNormol;
import com.whu.waterworks.model.QualityNormol;
import com.whu.waterworks.model.WaterPlantNorm;
import com.whu.waterworks.service.QualityReportDataService;

public class GetQualityReportDataAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private QualityReportDataService qualityReportDataService;
	// private QualityNormolService qualityNormolService; // 表1 水质常规指标及限值
	// private QualityNonNormService qualityNonNormService; //表3 水质非常规指标及限值
	// private //表2 饮用水中消毒剂常规指标及要求
	// private ArrayList<String> waterPlantNorm;
	// private WaterPlantNormService waterPlantNormService;
	private WaterPlantNorm norm;
	private String jonsStrOfName;
	private String code; // qualityNorm;qualityNonNorm;antisseptic;水厂ID
	private String month; //根据月份来获取数据
	private QualityNormol qualityNorm;
	private QualityNonNormol qualityNonNorm;
	private Antisseptic antisseptic;
	private JSONObject jsonObj;
	private QualityReportDataDto qualityReportDataDto;
	private JSONArray jArray;// = new JSONArray();
	private List<QualityReportDataDto> list;
	private List<QualityNormol> qualityNormList;
	private List<QualityNonNormol> qualityNonNormList;
	private List<Antisseptic> antissepticList;
	private static String[] tableStr = { "qualityNorm", "qualityNonNorm",
			"antisseptic" };
	private static Map<String, String> testItemMap = new HashMap<String, String>() {
		{
			put("ZDCGJQ1", "总大肠菌群（MPN/100mL或CFU/100mL）");
			put("NRDCGJQ1", "耐热大肠菌群（MPN/100mL或CFU/100mL）");
			put("DCAXSJ1", "大肠埃希氏菌（MPN/100mL或CFU/100mL）");
			put("JLZS1", "菌落总数（CFU/mL）");
			put("SHEN1", "砷（mg/L）");
			put("GE1", "镉（mg/L）");
			put("GEE1", "铬（六价，mg/L）");
			put("QIAN1", "铅（mg/L）");
			put("GONG1", "汞（mg/L）");
			put("QI1", "硒（mg/L）");
			put("QHW1", "氰化物（mg/L）");
			put("FHW1", "氟化物（mg/L）");
			put("NSY1", "硝酸盐（以N计，mg/L）");
			put("SLJW1", "三氯甲烷（mg/L）");
			put("SLHT1", "四氯化碳（mg/L）");
			put("XSY1", "溴酸盐（使用臭氧时，mg/L）");
			put("JQ1", "甲醛（使用臭氧时，mg/L）");
			put("YLSY1", "亚氯酸盐（使用二氧化氯消毒时，mg/L）");
			put("LSY1", "氯酸盐（使用复合二氧化氯消毒时，mg/L）");
			put("SD1", "色度（铂钴色度单位）");
			put("HZD1", "浑浊度（NTU-散射浊度单位）");
			put("XHW1", "臭和味");
			put("RYKJW1", "肉眼可见物");
			put("PH1", "pH （pH单位）");
			put("LV1", "铝（mg/L）");
			put("TIE1", "铁（mg/L）");
			put("MENG1", "锰（mg/L）");
			put("TONG1", "铜（mg/L）");
			put("XIN1", "锌（mg/L）");
			put("LHW1", "氯化物（mg/L）");
			put("LIUSY1", "硫酸盐（mg/L）");
			put("RJXZGT1", "溶解性总固体（mg/L）");
			put("ZYD1", "总硬度(以CaCO3计，mg/L）");
			put("HYL1", "耗氧量（CODMn法，以O2计，mg/L）");
			put("HFFL1", "挥发酚类（以苯酚计，mg/L）");
			put("YLZHCXDJ1", "阴离子合成洗涤剂（mg/L）");
			put("ZFSX11", "总α放射性（Bq/L");
			put("ZFSX21", "总β放射性（Bq/L）");
			put("JDBMC1", "贾第鞭毛虫（个/10L）");
			put("YBZC1", "隐孢子虫（个/10L）");
			put("TI1", "锑（mg/L）");
			put("BEI1", "钡（mg/L）");
			put("PI1", "铍（mg/L）");
			put("PENG1", "硼（mg/L）");
			put("MU1", "钼（mg/L）");
			put("LIE1", "镍（mg/L）");
			put("YIN1", "银（mg/L）");
			put("TA1", "铊（mg/L）");
			put("LHQ1", "氯化氰 （以CN-计，mg/L）");
			put("YLEXJW1", "一氯二溴甲烷（mg/L）");
			put("ELYXJW1", "二氯一溴甲烷（mg/L）");
			put("ELYS1", "二氯乙酸（mg/L）");
			put("YEELYW1", "1,2-二氯乙烷（mg/L）");
			put("ELJW1", "二氯甲烷（mg/L）");
			put("SLJWN1", "三卤甲烷");
			put("YYYSLYW1", "1,1,1-三氯乙烷（mg/L）");
			put("SLYS1", "三氯乙酸（mg/L）");
			put("SLYQ1", "三氯乙醛（mg/L）");
			put("ESLSLF1", "2,4,6-三氯酚（mg/L）");
			put("SXJW1", "三溴甲烷（mg/L）");
			put("QL1", "七氯（mg/L）");
			put("MLLL1", "马拉硫磷（mg/L）");
			put("WLF1", "五氯酚（mg/L）");
			put("LLL1", "六六六（总量，mg/L）");
			put("LLB1", "六氯苯（mg/L）");
			put("LG1", "乐果（mg/L）");
			put("DLL1", "对硫磷（mg/L）");
			put("MCS1", "灭草松（mg/L）");
			put("JJDLL1", "甲基对硫磷（mg/L）");
			put("BJQ1", "百菌清（mg/L）");
			put("FND1", "呋喃丹（mg/L）");
			put("LD1", "林丹（mg/L）");
			put("DSP1", "毒死蜱（mg/L）");
			put("CAOGL1", "草甘膦（mg/L）");
			put("DIDIW1", "敌敌畏（mg/L）");
			put("XFJ1", "莠去津（mg/L）");
			put("XIUJJZ1", "溴氰菊酯（mg/L）");
			put("ERSID1", "2,4-滴（mg/L）");
			put("DIDIT1", "滴滴涕（mg/L）");
			put("YIBEN1", "乙苯（mg/L）");
			put("ERJIAB1", "二甲苯（mg/L）");
			put("YYELYX1", "1,1-二氯乙烯（mg/L）");
			put("YEELYX1", "1,2-二氯乙烯（mg/L）");
			put("YEELB1", "1,2-二氯苯（mg/L）");
			put("YSELB1", "1,4-二氯苯（mg/L）");
			put("SLYX1", "三氯乙烯（mg/L）");
			put("SLB1", "三氯苯（总量，mg/L）");
			put("LFDEX1", "六氯丁二烯（mg/L）");
			put("BXXA1", "丙烯酰胺（mg/L）");
			put("SILYX1", "四氯乙烯（mg/L）");
			put("JIABEN1", "甲苯（mg/L）");
			put("LBEJSEZ1", "邻苯二甲酸二（2-乙基己基）酯（mg/L）");
			put("HYLBW1", "环氧氯丙烷（mg/L）");
			put("BEN1", "苯（mg/L）");
			put("BYX1", "苯乙烯（mg/L）");
			put("BBB1", "苯并(a)芘（mg/L）");
			put("LYX1", "氯乙烯（mg/L）");
			put("LBEN1", "氯苯（mg/L）");
			put("WLZDS1", "微囊藻毒素-LR（mg/L）");
			put("ANDAN1", "氨氮（以N计，mg/L）");
			put("LIUHW1", "硫化物（mg/L）");
			put("NA1", "钠（mg/L）");
			put("LVQI1", "氯气及游离氯制剂（游离氯,mg/L）");
			put("YLA1", "一氯胺（总氯，mg/L）");
			put("CY1", "臭氧（O3，mg/L）");
			put("EYHL1", "二氧化氯（ClO2，mg/L）");
		}
	};
	private static Map<String, String> testMethodMap = new HashMap<String, String>(){
        {
            put("总大肠菌群（MPN/100mL或CFU/100mL）","多管发酵法");
            put("耐热大肠菌群（MPN/100mL或CFU/100mL）","多管发酵法");
            put("大肠埃希氏菌（MPN/100mL或CFU/100mL）","多管发酵法");
            put("菌落总数（CFU/mL）","平皿计数法");
            put("砷（mg/L）", "氢化物原子荧光法");
            put("镉（mg/L）", "氢化物原子荧光法");
            put("铬（六价，mg/L）", "无火焰原子吸收分光光度法");
            put("铅（mg/L）", "无火焰原子吸收分光光度法");
            put("汞（mg/L）", "原子荧光法");
            put("硒（mg/L）", "石墨炉原子吸收法");
            put("氰化物（mg/L）","异烟酸-吡唑酮分光光度法");
            put("氟化物（mg/L）","离子选择电极法");
            put("硝酸盐（以N计，mg/L）","麝香草酚分光光度法");
            put("三氯甲烷（mg/L）", "顶空气相色谱法");
            put("四氯化碳（mg/L）","填充柱气相色谱法");
            put("溴酸盐（使用臭氧时，mg/L）", "离子色谱法-氢氧根系统淋洗液");
            put("甲醛（使用臭氧时，mg/L）", "4-氨基-3-联氨-5-巯基-1，2，4-三氮杂茂（AHMT）分光光度法");
            put("亚氯酸盐（使用二氧化氯消毒时，mg/L）", "碘量法");
            put("氯酸盐（使用复合二氧化氯消毒时，mg/L）", "碘量法");
            put("色度（铂钴色度单位）","铂-钴标准比色法");
            put("浑浊度（NTU-散射浊度单位）","散射法-福尔马肼");
            put("臭和味","嗅气和尝味法");
            put("肉眼可见物","直接观察法");
            put("pH （pH单位）","玻璃电极法");
            put("铝（mg/L）", "铬天青S分光光度法");
            put("铁（mg/L）", "原子吸收分光光度法");
            put("锰（mg/L）", "原子吸收分光光度法");
            put("铜（mg/L）", "无火焰原子吸收分光光度法");
            put("锌（mg/L）", "原子吸收分光光度法");
            put("氯化物（mg/L）","硝酸银容量法");
            put("硫酸盐（mg/L）","硫酸钡比浊法");
            put("溶解性总固体（mg/L）","称量法");
            put("总硬度(以CaCO3计，mg/L）","乙二胺四乙酸二钠滴定法");
            put("耗氧量（CODMn法，以O2计，mg/L）", "酸性高锰酸钾滴定法");
            put("挥发酚类","4-氨基安替吡啉三氯甲烷萃取分光光度法");
            put("阴离子合成洗涤剂","亚甲蓝分光光度法");
            put("总α放射性（Bq/L）", "低本底总α检测法");
            put("总β放射性（Bq/L）", "薄样法");
            put("贾第鞭毛虫（个/10L）","免疫磁分离荧光抗体法");
            put("隐孢子虫（个/10L）", "Envirochek方法");
            put("锑（mg/L）", "氢化物原子荧光法");
            put("钡（mg/L）", "无火焰原子吸收分光光度法");
            put("铍（mg/L）", "桑色素荧光分光光度法");
            put("硼（mg/L）","甲亚胺-H分光光度法");
            put("钼（mg/L）","无火焰原子吸收分光光度法");
            put("镍（mg/L）", "无火焰原子吸收分光光度法");
            put("银（mg/L）", "无火焰原子吸收分光光度法");
            put("铊（mg/L）", "无火焰原子吸收分光光度法");
            put("氯化氰 （以CN-计，mg/L）", "异烟酸-巴比妥酸分光光度法");
            put("一氯二溴甲烷（mg/L）", "填充柱气相色谱法");
            put("二氯一溴甲烷（mg/L）", "填充柱气相色谱法");
            put("二氯乙酸（mg/L）", "液液萃取衍生气相色谱法");
            put("1,2-二氯乙烷（mg/L）", "顶空气相色谱法");
            put("二氯甲烷（mg/L）", "顶空气相色谱法");
            put("三卤甲烷", "分光光度法");
            put("1,1,1-三氯乙烷（mg/L）", "气相色谱法");
            put("三氯乙酸（mg/L）", "液液萃取衍生气相色谱法");
            put("三氯乙醛（mg/L）", "气相色谱法");
            put("2,4,6-三氯酚（mg/L）", "衍生化气相色谱法");
            put("三溴甲烷（mg/L）", "填充柱气相色谱法");
            put("七氯（mg/L）","液液萃取气相色谱法");
            put("马拉硫磷（mg/L）", "填充柱气相色谱法");
            put("五氯酚（mg/L）", "衍生化气相色谱法");
            put("六六六（总量，mg/L）", "填充柱气相色谱法");
            put("六氯苯（mg/L）", "溶剂萃取-填充柱气相色谱法");
            put("乐果（mg/L）", "填充柱气相色谱法");
            put("对硫磷（mg/L）", "填充柱气相色谱法");
            put("灭草松（mg/L）", "气相色谱法");
            put("甲基对硫磷（mg/L）", "填充柱气相色谱法");
            put("百菌清（mg/L）", "气相色谱法");
            put("呋喃丹（mg/L）","高亚液相色谱法");
            put("林丹（mg/L）", "填充柱气相色谱法");
            put("毒死蜱（mg/L）", "气相色谱法");
            put("草甘膦（mg/L）", "高亚液相色谱法");
            put("敌敌畏（mg/L）", "填充柱气相色谱法");
            put("莠去津（mg/L）", "高亚液相色谱法");
            put("溴氰菊酯（mg/L）","气相色谱法");
            put("2,4-滴（mg/L）", "气相色谱法");
            put("滴滴涕（mg/L）", "填充柱气相色谱法");
            put("乙苯（mg/L）", "溶剂萃取-填充柱气相色谱法");
            put("二甲苯（mg/L）", "溶剂萃取-填充柱气相色谱法");
            put("1,1-二氯乙烯（mg/L）", "吹脱捕集气相色谱法");
            put("1,2-二氯乙烯（mg/L）", "吹脱捕集气相色谱法");
            put("1,2-二氯苯（mg/L）", "气相色谱法");
            put("1,4-二氯苯（mg/L）", "气相色谱法");
            put("三氯乙烯（mg/L）", "填充柱气相色谱法");
            put("三氯苯（总量，mg/L）", "气相色谱法");
            put("六氯丁二烯（mg/L）", "顶空气相色谱法");
            put("丙烯酰胺（mg/L）", "气相色谱法");
            put("四氯乙烯（mg/L）", "填充柱气相色谱法");
            put("甲苯（mg/L）", "溶剂萃取-填充柱气相色谱法");
            put("邻苯二甲酸二（2-乙基己基）酯（mg/L）", "气相色谱法");
            put("环氧氯丙烷（mg/L）", "气相色谱法");
            put("苯（mg/L）", "溶剂萃取-填充柱气相色谱法");
            put("苯乙烯（mg/L）", "溶剂萃取-填充柱气相色谱法");
            put("苯并(a)芘（mg/L）", "高压液相色谱法");
            put("氯乙烯（mg/L）", "填充柱气相色谱法");
            put("氯苯（mg/L）", "气相色谱法");
            put("微囊藻毒素-LR（mg/L）", "高压液相色谱法");
            put("氨氮（以N计，mg/L）","纳氏试剂分光光度法");
            put("硫化物（mg/L）","N,N-二乙基对苯二胺分光光度法");
            put("钠（mg/L）", "火焰原子吸收分光光度法");
            put("氯气及游离氯制剂（游离氯,mg/L）","碘量法");
            put("一氯胺（总氯，mg/L）","N,N-二乙基对苯二胺(DPD)分光光度法");
            put("臭氧（O3，mg/L）","碘量法");
            put("二氧化氯（ClO2，mg/L）","N,N-二乙基对苯二胺硫酸亚铁铵滴定法");
        }       
    };
	public String getQualityReportData() throws NoSuchMethodException,
			SecurityException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException {
		list = new ArrayList<>();
		int serialNumber = 0;// 设置序号
		System.out.println("code=" + code);
		WaterPlantNorm norm = qualityReportDataService
				.getWaterPlantNormById(code);
		if (null != norm) {
			String seletedNorm = norm.getSelectedNorm();
			JSONObject jsonObject = JSONObject.fromObject(seletedNorm);
			Iterator keyIter = jsonObject.keys();
			String key;
			Object value;
			Map<String, String> valueMap = new HashMap();
			while (keyIter.hasNext()) {
				key = (String) keyIter.next();
				value = jsonObject.get(key);
				// System.out.println("helloooooo" + value);
				valueMap.put(key, (String) value);
			}
			// QualityReportDataDto dto = new QualityReportDataDto();
			if (valueMap.containsKey(tableStr[0])) {
				String[] strs = valueMap.get(tableStr[0]).split("#");
				qualityNormList = qualityReportDataService.getQualityNormolByIdAndMonth(code, month);
				System.out.println("qualityNormList.size:"
						+ qualityNormList.size());
				for (String field : strs) {
					QualityReportDataDto dto = new QualityReportDataDto();
					++serialNumber;
					dto.setSerialNumber(String.valueOf(serialNumber));
					String keyTemp = field.toUpperCase();
					keyTemp = keyTemp + 1;
					String standardValue = new String();
					if (testItemMap.containsKey(keyTemp)) {
						dto.setTestItem(testItemMap.get(keyTemp));
						standardValue = qualityReportDataService
								.getQualityNormolStandardValue(keyTemp
										.toLowerCase());
						dto.setStandardValue(standardValue);
						if (standardValue == null
								|| standardValue.equals("不得检出")
								|| standardValue.equals("无")
								|| standardValue.equals("")
								|| standardValue.equals("null")) {
							standardValue = "0";
						}
					}
					if (testMethodMap.containsKey(testItemMap.get(keyTemp))) {
						dto.setTestMethod(testMethodMap.get(testItemMap.get(keyTemp)));						
					}
					for (int i = 1; i <= 3; i++) {
						String method = field + i;
						method = "get" + method.substring(0, 1).toUpperCase()
								+ method.substring(1);
						// 添加到数组
						List<String> values = new ArrayList<>();
						for (QualityNormol bean : qualityNormList) {

							Method m = bean.getClass().getMethod(method,
									(Class<?>[]) null);
							String v = String.valueOf(m.invoke(bean,
									(Object[]) null));
							values.add(v);
						}
						// 剔除无效数据
						List<String> effectValues = new ArrayList<>();
						for (String s : values) {
							if (s == null || s.equals("") || s.equals("无")
									|| s.equals("null")) {
								continue;
							}
//							else if(Character.isDigit(s.charAt(0))){
//								Double v = Double.parseDouble(s);
//								effectValues.add(v);
//							}
							else {								
								effectValues.add(s);
							}
						}
						// 对list排序
						// Collections.sort(effectValues,
						// new Comparator<Double>() {
						//
						// @Override
						// public int compare(Double o1, Double o2) {
						// // TODO Auto-generated method stub
						// if (o1 > o2)
						// return 1;
						// return -1;
						// }
						// });
						System.out.println("effectValues.size:"
								+ effectValues.size());
						if (!effectValues.isEmpty()) {
							if (i == 1) {
								// String maxValue1; //最高值
								// String minValue1; //最小值
								// String averageValue1; //平均值
								dto.setTestTimes1(String.valueOf(effectValues
										.size()));
								// dto.setMaxValue1(String.valueOf(effectValues.get(effectValues.size()
								// - 1)));
								dto.setMaxValue1(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue1(String.valueOf(Collections
										.min(effectValues)));
								// dto.setMinValue1(String.valueOf(effectValues.get(0)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue1(String.valueOf(result));

							} else if (i == 2) {
								// String testTimes2;
								// String maxValue2;
								// String minValue2;
								// String averageValue2;
								// String nonReachingTimes2; //未达标次数
								dto.setTestTimes2(String.valueOf(effectValues
										.size()));
								dto.setMaxValue2(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue2(String.valueOf(Collections
										.min(effectValues)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue2(String.valueOf(result));
								int count = 0;
//								for (Double d : effectValues) {
//									if (d > Double.parseDouble(standardValue))
//										count++;
//								}
								for (String s : effectValues) {
									if(standardValue.charAt(0)=='＜'){
										if (Double.parseDouble(s) >= Double.parseDouble(standardValue.substring(1)))
											count++;
									}else if(standardValue.charAt(0)=='≥'){
										if (Double.parseDouble(s) < Double.parseDouble(standardValue.substring(1)))
											count++;
									}else if(isNum(standardValue)){
										if (Double.parseDouble(s) > Double.parseDouble(standardValue))
											count++;
									}else{
										if (!s.equals(standardValue)){
											count++;
										}											
									}
								}
								dto.setNonReachingTimes2(String.valueOf(count));

							} else if (i == 3) {
								dto.setTestTimes3(String.valueOf(effectValues
										.size()));
								dto.setMaxValue3(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue3(String.valueOf(Collections
										.min(effectValues)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue3(String.valueOf(result));
								int count = 0;
								for (String s : effectValues) {
									if(standardValue.charAt(0)=='＜'){
										if (Double.parseDouble(s) >= Double.parseDouble(standardValue.substring(1)))
											count++;
									}else if(standardValue.charAt(0)=='≥'){
										if (Double.parseDouble(s) < Double.parseDouble(standardValue.substring(1)))
											count++;
									}else if(isNum(standardValue)){
										if (Double.parseDouble(s) > Double.parseDouble(standardValue))
											count++;
									}else{
										if (!s.equals(standardValue)){
											count++;
										}											
									}
								}
								dto.setNonReachingTimes3(String.valueOf(count));
							}
						}

					}
					list.add(dto);
				}
			}
			if (valueMap.containsKey(tableStr[1])) {
				String[] strs = valueMap.get(tableStr[1]).split("#");
				qualityNonNormList = qualityReportDataService.getQualityNonNormolByIdAndMonth(code, month);
				System.out.println("qualityNonNormList.size:"
						+ qualityNonNormList.size());
				for (String field : strs) {
					QualityReportDataDto dto = new QualityReportDataDto();
					++serialNumber;
					dto.setSerialNumber(String.valueOf(serialNumber));
					String keyTemp = field.toUpperCase();
					keyTemp = keyTemp + 1;
					String standardValue = new String();
					if (testItemMap.containsKey(keyTemp)) {
						dto.setTestItem(testItemMap.get(keyTemp));
						standardValue = qualityReportDataService
								.getQualityNonNormolStandardValue(keyTemp
										.toLowerCase());
						dto.setStandardValue(standardValue);
					}
					if (testMethodMap.containsKey(testItemMap.get(keyTemp))) {
						dto.setTestMethod(testMethodMap.get(testItemMap.get(keyTemp)));						
					}
					if (standardValue == null
							|| standardValue.equals("不得检出")
							|| standardValue.equals("无")
							|| standardValue.equals("")
							|| standardValue.equals("null")) {
						standardValue = "0";
					}
					System.out.println("standardValue-----:" + standardValue);
					for (int i = 1; i <= 3; i++) {
						String method = field + i;
						method = "get" + method.substring(0, 1).toUpperCase()
								+ method.substring(1);
						// 添加到数组
						List<String> values = new ArrayList<>();
						for (QualityNonNormol bean : qualityNonNormList) {
							Method m = bean.getClass().getMethod(method,
									(Class<?>[]) null);
							String v = String.valueOf(m.invoke(bean,
									(Object[]) null));
							values.add(v);
						}
						// 剔除无效数据
						List<String> effectValues = new ArrayList<>();
						for (String s : values) {
							if (s == null || s.equals("") || s.equals("无")
									|| s.equals("null")) {
								continue;
							}
//							else if(Character.isDigit(s.charAt(0))){
//								Double v = Double.parseDouble(s);
//								effectValues.add(v);
//							}
							else {								
								effectValues.add(s);
							}
						}
						// 对list排序
						// Collections.sort(effectValues,
						// new Comparator<Double>() {
						//
						// @Override
						// public int compare(Double o1, Double o2) {
						// // TODO Auto-generated method stub
						// if (o1 > o2)
						// return 1;
						// return -1;
						// }
						// });
						System.out.println("effectValues.size:"
								+ effectValues.size());
						if (!effectValues.isEmpty()) {
							if (i == 1) {
								// String maxValue1; //最高值
								// String minValue1; //最小值
								// String averageValue1; //平均值
								dto.setTestTimes1(String.valueOf(effectValues
										.size()));
								// dto.setMaxValue1(String.valueOf(effectValues.get(effectValues.size()
								// - 1)));
								dto.setMaxValue1(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue1(String.valueOf(Collections
										.min(effectValues)));
								// dto.setMinValue1(String.valueOf(effectValues.get(0)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue1(String.valueOf(result));

							} else if (i == 2) {
								// String testTimes2;
								// String maxValue2;
								// String minValue2;
								// String averageValue2;
								// String nonReachingTimes2; //未达标次数
								dto.setTestTimes2(String.valueOf(effectValues
										.size()));
								dto.setMaxValue2(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue2(String.valueOf(Collections
										.min(effectValues)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue2(String.valueOf(result));
								int count = 0;
								System.out.println("standardValue2222:"
										+ standardValue);
								for (String s : effectValues) {
									if(standardValue.charAt(0)=='＜'){
										if (Double.parseDouble(s) >= Double.parseDouble(standardValue.substring(1)))
											count++;
									}else if(standardValue.charAt(0)=='≥'){
										if (Double.parseDouble(s) < Double.parseDouble(standardValue.substring(1)))
											count++;
									}else if(isNum(standardValue)){
										if (Double.parseDouble(s) > Double.parseDouble(standardValue))
											count++;
									}else{
										if (!s.equals(standardValue)){
											count++;
										}											
									}
								}
								dto.setNonReachingTimes2(String.valueOf(count));

							} else if (i == 3) {
								dto.setTestTimes3(String.valueOf(effectValues
										.size()));
								dto.setMaxValue3(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue3(String.valueOf(Collections
										.min(effectValues)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue3(String.valueOf(result));
								int count = 0;
								for (String s : effectValues) {
									if(standardValue.charAt(0)=='＜'){
										if (Double.parseDouble(s) >= Double.parseDouble(standardValue.substring(1)))
											count++;
									}else if(standardValue.charAt(0)=='≥'){
										if (Double.parseDouble(s) < Double.parseDouble(standardValue.substring(1)))
											count++;
									}else if(isNum(standardValue)){
										if (Double.parseDouble(s) > Double.parseDouble(standardValue))
											count++;
									}else{
										if (!s.equals(standardValue)){
											count++;
										}											
									}
								}
								dto.setNonReachingTimes3(String.valueOf(count));
							}
						}

					}
					list.add(dto);
				}
			}
			if (valueMap.containsKey(tableStr[2])) {
				String[] strs = valueMap.get(tableStr[2]).split("#");
				antissepticList = qualityReportDataService.getAntissepticByIdAndMonth(code, month);
				System.out.println("antissepticList.size:"
						+ antissepticList.size());
				for (String field : strs) {
					QualityReportDataDto dto = new QualityReportDataDto();
					++serialNumber;
					dto.setSerialNumber(String.valueOf(serialNumber));
					String keyTemp = field.toUpperCase();
					keyTemp = keyTemp + 1;
					String standardValue1 = new String();
					String standardValue2 = new String();
					String standardValue3 = new String();
					if (testItemMap.containsKey(keyTemp)) {
						dto.setTestItem(testItemMap.get(keyTemp));
						standardValue1=qualityReportDataService
								.getAntissepticStandardValue(field + "1");
						standardValue2=qualityReportDataService
								.getAntissepticStandardValue(field
										+ "2");
						standardValue3=qualityReportDataService
								.getAntissepticStandardValue(field
										+ "3");
						String standardValueTemp = standardValue1+","+standardValue2+","+standardValue3;						
						dto.setStandardValue(standardValueTemp);
					}
					if (standardValue1 == null
							|| standardValue1.equals("不得检出")
							|| standardValue1.equals("无")
							|| standardValue1.equals("")
							|| standardValue1.equals("null")) {
						standardValue1 = "0";
					}
					if (standardValue2 == null
							|| standardValue2.equals("不得检出")
							|| standardValue2.equals("无")
							|| standardValue2.equals("")
							|| standardValue2.equals("null")) {
						standardValue2 = "0";
					}
					if (standardValue3 == null
							|| standardValue3.equals("不得检出")
							|| standardValue3.equals("无")
							|| standardValue3.equals("")
							|| standardValue3.equals("null")) {
						standardValue3 = "0";
					}
					if (testMethodMap.containsKey(testItemMap.get(keyTemp))) {
						dto.setTestMethod(testMethodMap.get(testItemMap.get(keyTemp)));						
					}
					for (int i = 1; i <= 3; i++) {
						String method = field + i;
						method = "get" + method.substring(0, 1).toUpperCase()
								+ method.substring(1);
						// 添加到数组
						List<String> values = new ArrayList<>();
						for (Antisseptic bean : antissepticList) {
							Method m = bean.getClass().getMethod(method,
									(Class<?>[]) null);
							String v = String.valueOf(m.invoke(bean,
									(Object[]) null));
							values.add(v);
						}
						// 剔除无效数据
						List<String> effectValues = new ArrayList<>();
						for (String s : values) {
							if (s == null || s.equals("") || s.equals("无")
									|| s.equals("null")) {
								continue;
							}
//							else if(Character.isDigit(s.charAt(0))){
//								Double v = Double.parseDouble(s);
//								effectValues.add(v);
//							}
							else {								
								effectValues.add(s);
							}
						}
						// 对list排序
						// Collections.sort(effectValues,
						// new Comparator<Double>() {
						//
						// @Override
						// public int compare(Double o1, Double o2) {
						// // TODO Auto-generated method stub
						// if (o1 > o2)
						// return 1;
						// return -1;
						// }
						// });
						System.out.println("effectValues.size:"
								+ effectValues.size());
						if (!effectValues.isEmpty()) {
							if (i == 1) {
								// String maxValue1; //最高值
								// String minValue1; //最小值
								// String averageValue1; //平均值
								dto.setTestTimes1(String.valueOf(effectValues
										.size()));
								dto.setMaxValue1(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue1(String.valueOf(Collections
										.min(effectValues)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue1(String.valueOf(result));

							} else if (i == 2) {
								// String testTimes2;
								// String maxValue2;
								// String minValue2;
								// String averageValue2;
								// String nonReachingTimes2; //未达标次数
								dto.setTestTimes2(String.valueOf(effectValues
										.size()));
								dto.setMaxValue2(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue2(String.valueOf(Collections
										.min(effectValues)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue2(String.valueOf(result));
								int count = 0;
								System.out.println("standardValue2---:"
										+ standardValue2);
								for (String s : effectValues) {
									if(standardValue2.charAt(0)=='＜'){
										if (Double.parseDouble(s) >= Double.parseDouble(standardValue2.substring(1)))
											count++;
									}else if(standardValue2.charAt(0)=='≥'){
										if (Double.parseDouble(s) < Double.parseDouble(standardValue2.substring(1)))
											count++;
									}else if(isNum(standardValue2)){
										if (Double.parseDouble(s) > Double.parseDouble(standardValue2))
											count++;
									}else{
										if (!s.equals(standardValue2)){
											count++;
										}											
									}
								}
								dto.setNonReachingTimes2(String.valueOf(count));

							} else if (i == 3) {
								dto.setTestTimes3(String.valueOf(effectValues
										.size()));
								dto.setMaxValue3(String.valueOf(Collections
										.max(effectValues)));
								dto.setMinValue3(String.valueOf(Collections
										.min(effectValues)));
								Double sum = 0.0;
								for (String s : effectValues) {
									if(Character.isDigit(s.charAt(0))){
										sum += Double.parseDouble(s);
									}									
								}
								double dtemp = sum / effectValues.size();
								BigDecimal b = new BigDecimal(dtemp);
								double result = b.setScale(3,
										BigDecimal.ROUND_HALF_UP).doubleValue();
								dto.setAverageValue3(String.valueOf(result));
								int count = 0;
								for (String s : effectValues) {
									if(standardValue3.charAt(0)=='＜'){
										if (Double.parseDouble(s) >= Double.parseDouble(standardValue3.substring(1)))
											count++;
									}else if(standardValue3.charAt(0)=='≥'){
										if (Double.parseDouble(s) < Double.parseDouble(standardValue3.substring(1)))
											count++;
									}else if(isNum(standardValue3)){
										if (Double.parseDouble(s) > Double.parseDouble(standardValue3))
											count++;
									}else{
										if (!s.equals(standardValue3)){
											count++;
										}											
									}
								}
								dto.setNonReachingTimes3(String.valueOf(count));
							}
						}

					}
					list.add(dto);
				}
			}

		}
		return SUCCESS;
	}
	public static boolean isNum(String str){
		return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$");
	}
	// if(valueMap.containsKey(tableStr[0])){
	// String tempStr1=(String) valueMap.get(tableStr[0]);
	// String[] key1=tempStr1.split("#");
	// for(String s:key1){
	// qualityNormList.add(s);
	//
	// System.out.println("hellooooookey1"+s);
	// }
	//
	// }
	// System.out.println("hellooooookey1"+qualityNorm);
	// if(valueMap.containsKey(tableStr[1])){
	// String tempStr2=(String) valueMap.get(tableStr[1]);
	// String[] key2=tempStr2.split("#");
	// for(String s:key2){
	// System.out.println("hellooooookey2"+s);
	// }
	//
	// }
	// if(valueMap.containsKey(tableStr[2])){
	// String tempStr3=(String) valueMap.get(tableStr[2]);
	// String[] key3=tempStr3.split("#");
	// for(String s:key3){
	// System.out.println("hellooooookey3"+s);
	// }
	// }
	public String getDataFromQualityNorm() {
		list = new ArrayList<>();
		antissepticList = qualityReportDataService.getAntissepticById(code);
		antisseptic = qualityReportDataService.getLimitedAntisseptic();
		System.out.println("qualityNonNormList---" + qualityNonNormList);
		QualityReportDataDto dto = new QualityReportDataDto();
		String s = "LVQI1";
		s = s.toLowerCase();
		String ss = qualityReportDataService.getAntissepticStandardValue(s);
		dto.setStandardValue(ss);
		dto.setAverageValue1("12");
		dto.setMaxValue1("5");
		dto.setAverageValue2("3");
		list.add(dto);
		QualityReportDataDto dto1 = new QualityReportDataDto();
		dto1.setAverageValue2("12");
		dto1.setMaxValue2("5");
		dto1.setAverageValue1("3");
		list.add(dto1);
		return SUCCESS;
	}

	@Override
	public String execute() throws Exception {

		return SUCCESS;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public JSONObject getJsonObj() {
		return jsonObj;
	}

	public void setJsonObj(JSONObject jsonObj) {
		this.jsonObj = jsonObj;
	}

	public JSONArray getjArray() {
		return jArray;
	}

	public void setjArray(JSONArray jArray) {
		this.jArray = jArray;
	}

	public List<QualityReportDataDto> getList() {
		return list;
	}

	public void setList(List<QualityReportDataDto> list) {
		this.list = list;
	}

	public QualityReportDataService getQualityReportDataService() {
		return qualityReportDataService;
	}

	public void setQualityReportDataService(
			QualityReportDataService qualityReportDataService) {
		this.qualityReportDataService = qualityReportDataService;
	}

	public QualityNormol getQualityNorm() {
		return qualityNorm;
	}

	public void setQualityNorm(QualityNormol qualityNorm) {
		this.qualityNorm = qualityNorm;
	}

	public WaterPlantNorm getNorm() {
		return norm;
	}

	public void setNorm(WaterPlantNorm norm) {
		this.norm = norm;
	}

	public String getJonsStrOfName() {
		return jonsStrOfName;
	}

	public void setJonsStrOfName(String jonsStrOfName) {
		this.jonsStrOfName = jonsStrOfName;
	}

	public List<QualityNormol> getQualityNormList() {
		return qualityNormList;
	}

	public void setQualityNormList(List<QualityNormol> qualityNormList) {
		this.qualityNormList = qualityNormList;
	}

	public QualityReportDataDto getQualityReportDataDto() {
		return qualityReportDataDto;
	}

	public void setQualityReportDataDto(
			QualityReportDataDto qualityReportDataDto) {
		this.qualityReportDataDto = qualityReportDataDto;
	}

	public QualityNonNormol getQualityNonNorm() {
		return qualityNonNorm;
	}

	public void setQualityNonNorm(QualityNonNormol qualityNonNorm) {
		this.qualityNonNorm = qualityNonNorm;
	}

	public Antisseptic getAntisseptic() {
		return antisseptic;
	}

	public void setAntisseptic(Antisseptic antisseptic) {
		this.antisseptic = antisseptic;
	}
	public String getMonth() {
		return month;
	}
	public void setMonth(String month) {
		this.month = month;
	}
}
